package main
//创建100万用户
import (
	account "git.oschina.net/fanbuchi/xgggh/oauth2/proto/account"
	"time"
	"fmt"
	"git.oschina.net/fanbuchi/xgggh/oauth2/db"
	"git.oschina.net/fanbuchi/xgggh/oauth2/model"
	"log"
	"git.oschina.net/fanbuchi/xgggh/oauth2/test/password"
)
func main() {
	//1. register clients
		client:=model.Client{
			Name:"android_app_redbags",
			Key:"key1234567890",
			Secret:"secret1234567890",
		}
		db.GetDB().Create(&client)
	//2.register role
		user:=model.Role{Name:"user",Description:"normal consumer"}
		dev:=model.Role{Name:"dev",Description:"developer"}
		superuser:=model.Role{Name:"superuser",Description:"superuser consumer"}
		admin:=model.Role{Name:"admin",Description:"admin manage"}

		db.GetDB().Create(&user)
		db.GetDB().Create(&dev)
		db.GetDB().Create(&superuser)
		db.GetDB().Create(&admin)

	start:=time.Now().UnixNano()
	base:=15108280907
	max :=15108280907 +2
	pass,_:=password.HashPassword("qw123456")
	for i:=base;i< max;i++  {
		v:=fmt.Sprint(i)
		req:=account.CreateReq{UserName:v,
		Password:string(pass),
		MetaAccountId:"20170523-3",
		RoleId:int64(user.ID)}

		account:=model.Account{UserName:req.UserName,
			RoleId:req.RoleId,
			MetaAccountId:req.MetaAccountId,
			Password:req.Password}

		err:=db.GetDB().Create(&account).Error
		if err !=nil{
			log.Println(err)
		}
	}

	end:=time.Now().UnixNano()
	fmt.Println((max-base)," times ----->",(end-start)/1000000000.00000000000000)
}


